<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <meta name="robots" content="INDEX,FOLLOW" />

        <script language="javascript" type="text/javascript" src="http://st.f2.vnecdn.net/j/v9/jquery-1.7.1.min.js"></script>
        <script>
            var base_url = '/';
            var jq = jQuery.noConflict();
            function addprojectquestion() {
                var sCheck = "";
                eventsid = jq('#cboCode').val();
                q1 = jq('#txtq1').val();
                q2 = jq('#txtq2').val();
                q3 = jq('#txtq3').val();

                if (jq('#txtquestion').length > 0) {
                    sCheck = replaceTag(trim(jq('#txtquestion').val()));

                    jq('#txtquestion').val(sCheck);
                    if (trimAll(sCheck) == '') {
                        alert('Bạn chưa nhập nội dung câu hỏi.');
                        jq('#txtquestion').focus();
                        return false;
                    }
                }



                var strpost = 'question=' + jq('#txtquestion').val();
                strpost += '&id=' + eventsid;
                strpost += '&q1=' + q1;
                strpost += '&q2=' + q2;
                strpost += '&q3=' + q3;

                alert(strpost);
                jq.ajax({
                    type: "POST",
                    cache: false,
                    url: base_url + "backend/createquestion/addquestion",
                    data: strpost,
                    timeout: 600000,
                    error: function(xhr, ajaxOptions, thrownError) {
                        alert("có lỗi xảy ra");
                    },
                    success: function(data) {
                        alert(data);
                        if (data == "ok")
                        {
                            alert("Thêm mới câu hỏi thành công");
                        }
                    }
                });


            }

            function changeProjectQuestion() {
                eventsid = jq('#cboCode').val();
                jq.ajax({
                    url: base_url + "backend/create/getprojectbyid/?id=" + eventsid
                }).done(function(html) {

                    // var obj = jQuery.parseJSON(html);


                    // jq('#txtname').val(obj.name_project);
                    // jq('#txtlinkvideo').val(obj.video_project);
                    // jq('#idproject').val(obj.id);
                    //location.reload();
                });
            }

            function changeQuestion() {
                vid = jq('#cboCodeP').val();

                // alert(vid);
                jq.ajax({
                    url: base_url + "backend/createquestion/getprojectbyid/?id=" + vid
                }).done(function(html) {
                    // alert(html);
                    jq('#cboquestion').append(html);



                    //var obj = jQuery.parseJSON(html);
                    // jq('#txtname').val(obj.name_project);
                    // jq('#txtlinkvideo').val(obj.video_project);
                    // jq('#idproject').val(obj.id);
                    //location.reload();
                });
            }


            function changeQuestion1() {
                questionid = jq('#cboquestion').val();
                jq.getJSON(
                        base_url + "backend/createquestion/getanswerbyid/?id=" + questionid,
                        function(data) {
                            jq.each(data, function(i, item) {
                                alert(item.content);
                            });
                        }
                );
                // alert(questionid);
                /*    jq.ajax({
                 url:  base_url+ "backend/createquestion/getanswerbyid/?id="+questionid
                 }).done(function(html) {
                 var obj = jQuery.parseJSON(html);
                 alert(obj.id_project);
                 //jq('#txtname').val(obj.name_project);
                 // jq('#txtquestion').val(obj.ContentQuestion);
                 
                 });*/
            }


            function checkEmail(txt) {
                txt = trim(txt).toLowerCase();
                var patt = /^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,6}$/;
                return (txt.match(patt) != null);
            }
            function trim(iStr) {
                if (iStr.length > 0) {
                    while (iStr.charCodeAt(0) <= 32)
                        iStr = iStr.substr(1);
                    while (iStr.charCodeAt(iStr.length - 1) <= 32)
                        iStr = iStr.substr(0, iStr.length - 1);
                }
                return iStr;
            }

            function trimAll(iStr) {
                if (iStr.length > 0) {
                    while (iStr.charCodeAt(0) <= 32)
                        iStr = iStr.substr(1);
                    while (iStr.charCodeAt(iStr.length - 1) <= 32)
                        iStr = iStr.substr(0, iStr.length - 1);
                }
                return iStr.replace(/ |&nbsp;/gi, '');
            }

            function replaceTag(txt) {
                txt = txt.replace(/</gi, '');
                txt = txt.replace(/>/gi, '');
                txt = txt.replace(/&/gi, '');
                return txt;
            }
        </script>




    </head>
    <body>


        <form name="frmadd" id="frmadd" method="post" enctype="multipart-formdata">
            <fieldset>
                <legend>tạo câu hỏi</legend>
                <?php //var_dump('<pre>',$data['project']); ?>
                <select name="cboCode" id="cboCode" style="width:280px;height:22px;" onchange="changeProjectQuestion();">

                    <?php
                    foreach ($data['project'] as $subcate) {
                        ?>
                        <option value="<?php echo($subcate['id']) ?>"><?php echo($subcate['name_project']) ?></option>

                        <?php
                        //var_dump( $subcate['name_project']);
                    }
                    ?>   
                </select>

                <label>Nội dung</label><input type="text" name="txtquestion" value="" id="txtquestion" size="30"><br>

                        <legend>tạo câu trả lời</legend>
                        <label>Câu trả lời 1</label><input type="text" name="txtq1" value="" id="txtq1" size="30"><br>
                                <label>Câu trả lời 2</label><input type="text" name="txtq2" value="" id="txtq2" size="30"><br>
                                        <label>Câu trả lời 3</label><input type="text" name="txtq3" value="" id="txtq3" size="30"><br>
                                                <label>&nbsp;</label> <input type="button" name="ok" value="Tao cau hoi" onclick="return addprojectquestion();"><br>

                                                        </fieldset>
                                                        </form>



                                                        <form name="frmadd" id="frmadd" method="post" enctype="multipart-formdata">
                                                            <fieldset>
                                                                <legend>Update các loại câu hỏi</legend>
                                                                <?php //var_dump('<pre>',$data['project']);  ?>
                                                                <label>Dự án</label>

                                                                <select name="cboCodeP" id="cboCodeP" style="width:280px;height:22px;" onchange="changeQuestion();">

                                                                    <?php
                                                                    foreach ($data['project'] as $subcate) {
                                                                        ?>
                                                                        <option value="<?php echo($subcate['id']) ?>"><?php echo($subcate['name_project']) ?></option>

                                                                        <?php
                                                                        //var_dump( $subcate['name_project']);
                                                                    }
                                                                    ?>   
                                                                </select> <br>


                                                                    <label>Câu hỏi nội dung</label>
                                                                    <select name="cboquestion" id="cboquestion" style="width:280px;height:22px;" onchange="changeQuestion1();">

                                                                    </select>

                                                                    <br> <br>
                                                                            <br>
                                                                                <legend>cập nhập câu trả lời</legend>
                                                                                <label>Nội dung</label><input type="text" name="txtquestion" value="" id="txtquestion" size="30"><br>
                                                                                        <label>Câu trả lời 1</label><input type="text" name="txtq1" value="" id="txtq1" size="30"><br>
                                                                                                <label>Câu trả lời 2</label><input type="text" name="txtq2" value="" id="txtq2" size="30"><br>
                                                                                                        <label>Câu trả lời 3</label><input type="text" name="txtq3" value="" id="txtq3" size="30"><br>
                                                                                                                <label>&nbsp;</label> <input type="button" name="ok" value="Tao cau hoi" onclick="return addprojectquestion();"><br>

                                                                                                                        </fieldset>
                                                                                                                        </form>


                                                                                                                        </body>
                                                                                                                        </html>